package DiskManager;


public class Disk {
      int[] FAT = new int[256];
      private DiskBit[] diskBit = new DiskBit[256];
      public Disk() {
    	  FAT[0] = 257;
    	  FAT[1] = 257;
    	   for(int i = 2;i < 256;i++)
    	  {
    		FAT[i] = 0;
    		diskBit[i]= new DiskBit(i);
    	  }   	
    	   FAT[2] = -1;
    	   FAT[3] = -1;
    	   FAT[163] = -1;
    	   FAT[123] = -1;
    	   FAT[183] = -1;
      }
      
      
    
	public int[] getFAT() {
    	  return FAT;
      }
      
      
      public void save(int bitnum,char[] content)
      {
    	  getDiskBit()[bitnum].save(content);
      }
      
      public String load(int starnum) {     
    	  String Content = null;
    	  int index = starnum;
    	  while(FAT[index]==-1)
    	  {
    		  Content = Content + String.copyValueOf(getDiskBit()[index].load());
    		  index = FAT[index];
    	  }
    	  return Content;
      }
      
     public void delete(int starnum) {
    	 
    	 int index = starnum;
   	  while(FAT[index]==-1)
   	  {
   		  getDiskBit()[index].clear();
   		  index = FAT[index];
   	  }
                                    }


	public DiskBit[] getDiskBit() {
		return diskBit;
	}


	public void setDiskBit(DiskBit[] diskBit) {
		this.diskBit = diskBit;
	}
    public void setFAT(int index,int newnum)
    {
    	FAT[index] = newnum;
    }
	
}
